package com.laizhenghua.demo.async;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;

/**
 * TODO
 *
 * @Description
 * @Author laizhenghua
 * @Date 2023/8/31 10:43
 **/
@Component
@EnableAsync
public class AsyncExecutor {
    private final Logger log = LoggerFactory.getLogger(getClass());

    @Async("executor")
    public CompletableFuture<String> asyncTest() {
        String name = Thread.currentThread().getName();
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info(name);
        return CompletableFuture.completedFuture(name);
    }
}
